Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 Search this book:
Previous | Table of Contents | Next
### OLE DB OLE DB is a set of Component Object Model (COM) interfaces that provide programmers with access to a variety of information sources. The goal of OLE DB is to provide universal data access—access that can deal with any type of data, regardless of its format, and that is not restricted to certain data sources. The OLE DB interfaces support the data management capabilities of each type of data source. OLE DB is not accessed directly from Visual Basic, but instead is accessed indirectly via ActiveX Data Objects (ADO). ### ADO ActiveX Data Objects provide Visual Basic programmers with an application-level interface to OLE DB. You rarely, if ever, need to worry about OLE DB—it’s just there doing its job—so you can think of ADO as an interface directly to the data source. ADO is new in this release of Visual Basic and is considered by Microsoft to be its “premier” data access technology. If you have used earlier versions of Visual Basic for database programming, you may be familiar with the older technologies: Remote Data Objects (RDO) and Data Access Objects (DAO). These technologies are still supported by Visual Basic. In fact, the Data control, used in the sample application developed in Chapter 19, makes use of these older technologies. However, for new projects, you should use ADO. Two ways exist to use ADO: directly in code or indirectly via the ADO Data Control. #### Accessing ADO In Code The ADO model contains seven classes. As with any other object-oriented model, to use the ADO classes, you first must create instances of them (objects) and then work with those objects’ methods and properties. For example, two of the objects in ADO are Connection and Command. To use these objects, you must first create instances of them, as follows:
    Dim con As New ADODB.Connection
    Dim cmd As New ADODB.Command
Then, you associate the Connection object with a specific data source:
    con.ConnectionString = “YourConnectionString”
    con.ConnectionTimeout = 30
    con.Open
Next, specify a command and associate it with the Connection object:
    cmd.Name = “YourCommand”
    cmd.ActiveConnection = con
A lot more details are involved, of course, but this should give you the general idea. Direct manipulation of ADO is done in code, without any visual controls directly involved in the process. #### ADO Data Control The other way to access objects in ADO is to use the ADO Data Control. This control is conceptually identical to the intrinsic Data Control that is used in Chapter 19. When placed on a form, the ADO Data Control looks like Figure 20.1. It is linked to a data source and to one or more data-aware controls. The ADO Data Control lets the user move from record to record in the database, and the data is automatically displayed in the data-aware controls. Changes to the data are automatically written to the data source. More details for the ADO Data Control are provided in the database project that is developed in later chapters. ### ODBC Open Database Connectivity (ODBC) provides an Applications Programming Interface (API) that contains procedures for performing various data-manipulation tasks. A program calls these API procedures, as needed, and the ODBC Driver Manager passes the calls to the appropriate driver. Appropriate means the driver that is designed for the particular data source that is in use. This is where the open part of the ODBC name comes from. Any data source publisher can write an ODBC driver for its own data format. ODBC is generally considered obsolete. The only reason to use ODBC in a new database project is if you need to access a data source that is in an obscure format, unsupported by ADO, for which an ODBC driver exists. Even in this situation, you probably are better off opting to use DAO, because it supports ODBC databases. ### DAO Data Access Objects (DAO) is similar to ODBC in that it provides an API that your program can call to perform data-manipulation tasks. DAO differs from ODBC in that it uses the Microsoft Jet Database Engine rather than a driver provided by the data source publisher. DAO is optimized to work with data source files in the MDB format (the same format used by the Microsoft Access database program). However, DAO also supports ODBC databases, as well as data sources in a variety of formats, including Paradox, FoxPro, dBase, Excel, and Lotus 1-2-3. Figure 20.1 The ADO Data Control. ### RDO The Remote Data Objects (RDO) programming model was developed specifically to deal with the special requirements of accessing the data source via a network, referred to as remote data access. RDO works by adding a layer on top of ODBC to handle the special needs of remote access, such as establishing connections and creating results sets. In some situations, RDO works with DAO to perform the required tasks. RDO can be implemented totally in code or via the RemoteData control. Implementing RDO in a Visual Basic application is very similar to using DAO. In fact, a Visual Basic application that uses the Data control and DAO can easily be converted to use the RemoteData control and RDO. The few differences arise primarily because RDO is designed for use only with strictly relational databases. RDO relies on the data source to process queries because RDO has no query processor of its own. ### The Bottom Line You probably aren’t too interested in memorizing the details of every database technology that Visual Basic supports. My bet is that you are more concerned with writing programs and want to know which database technology you should use. Fortunately, the answer is simple: Use ADO. This is not just my opinion, it is Microsoft’s opinion as well. Using ADO makes sense, of course, because ADO is the latest database technology and as such, it improves on and simplifies capabilities of the earlier technologies. Even so, you should know at least a little bit about the other database programming techniques, particularly if you are a professional programmer. You never know when a paying client will ask you to modify an existing Visual Basic database program that was written before ADO came on the scene.
Previous | Table of Contents | Next

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.